import os
import zipfile
import configparser

config = configparser.ConfigParser()
config.read('../Config/config.ini')


project_path = config.get('ProjectInfo', 'project_path')
project_name = config.get('ProjectInfo', 'project_name')
clientconfig = config.get('BuildInfo', 'clientconfig')
platform = config.get('BuildInfo', 'platform')


def get_version():
    with open(project_path + "/" + project_name + '/Config/Version.ini', 'r') as f:
        return f.read().strip()


source_dir = f"../../Builds/{get_version()}/{clientconfig}/{platform}/"


def ArchiveBuild():    
    print("Started archiving the folder...")
    with zipfile.ZipFile(f'{source_dir}/{project_name}_{get_version()}_{clientconfig}.zip', 'w', compression=zipfile.ZIP_DEFLATED) as myzip:
        for root, dirs, files in os.walk(source_dir):
            for file in files:
                absolute_path = os.path.join(root, file)
                myzip.write(absolute_path, os.path.relpath(absolute_path, source_dir))
    print("Archiving is complete")
